home *** CD-ROM | disk | FTP | other *** search
- package icontrols.DataNavigator;
-
- import com.ms.ado.DataSource;
- import com.ms.ado.Recordset;
- import com.ms.ado.adodb._Recordset;
- import com.ms.wd.app.Message;
- import com.ms.wd.core.Component;
- import com.ms.wd.core.Event;
- import com.ms.wd.core.EventHandler;
- import com.ms.wd.ui.Bitmap;
- import com.ms.wd.ui.Brush;
- import com.ms.wd.ui.Color;
- import com.ms.wd.ui.Control;
- import com.ms.wd.ui.Graphics;
- import com.ms.wd.ui.PaintEvent;
- import com.ms.wd.ui.Pen;
- import com.ms.wd.ui.Rectangle;
- import com.ms.wd.win32.Windows;
- import icontrols.HotButton;
-
- public class DataNavigator extends Control {
- private String m_dataMember = null;
- private DataSource m_dataSource = null;
- private Recordset m_recordset = null;
- private Brush m_backgroundBrush = null;
- private Brush m_textBackgroundBrush = null;
- private HotButton m_first = null;
- private HotButton m_previous = null;
- private HotButton m_next = null;
- private HotButton m_last = null;
- private static final int BUTTON_WIDTH = 20;
-
- public void onPrevious(Object sender, Event e) {
- if (this.m_recordset != null) {
- try {
- this.m_recordset.movePrevious();
- } catch (Exception var4) {
- }
- }
-
- }
-
- public final DataSource getDataSource() {
- return this.m_dataSource;
- }
-
- public void onLast(Object sender, Event e) {
- if (this.m_recordset != null) {
- try {
- this.m_recordset.moveLast();
- } catch (Exception var4) {
- }
- }
-
- }
-
- public void setDataSource(DataSource dataSource) {
- this.releaseRowset();
- this.m_dataSource = dataSource;
- this.acquireRowset();
- }
-
- protected void propertyChanged(int property) {
- super.propertyChanged(property);
- if (property == 5) {
- ((Control)this).invalidate();
- }
-
- }
-
- protected void setButtonEnabled(boolean enabled) {
- this.m_first.setEnabled(enabled);
- this.m_previous.setEnabled(enabled);
- this.m_next.setEnabled(enabled);
- this.m_last.setEnabled(enabled);
- }
-
- public DataNavigator() {
- this.m_first = new HotButton();
- this.m_previous = new HotButton();
- this.m_next = new HotButton();
- this.m_last = new HotButton();
- this.m_first.addOnClick(new EventHandler(this, "onFirst"));
- this.m_previous.addOnClick(new EventHandler(this, "onPrevious"));
- this.m_next.addOnClick(new EventHandler(this, "onNext"));
- this.m_last.addOnClick(new EventHandler(this, "onLast"));
- this.m_first.setImage((new Bitmap(((Component)this).getResource("First.bmp"))).getTransparentBitmap(true));
- this.m_next.setImage((new Bitmap(((Component)this).getResource("Next.bmp"))).getTransparentBitmap(true));
- this.m_previous.setImage((new Bitmap(((Component)this).getResource("Previous.bmp"))).getTransparentBitmap(true));
- this.m_last.setImage((new Bitmap(((Component)this).getResource("Last.bmp"))).getTransparentBitmap(true));
- ((Control)this).add(this.m_first);
- ((Control)this).add(this.m_previous);
- ((Control)this).add(this.m_next);
- ((Control)this).add(this.m_last);
- ((Control)this).setBounds(0, 0, 141, 25);
- this.setButtonEnabled(false);
- }
-
- private final void acquireRowset() {
- if (this.m_dataSource != null) {
- Object member = this.m_dataSource.getDataMember(this.m_dataMember, _Recordset.iid);
- if (member != null) {
- Recordset source = null;
- _Recordset rs = null;
-
- try {
- rs = (_Recordset)member;
- } catch (Exception var6) {
- }
-
- if (rs == null) {
- try {
- source = (Recordset)member;
- } catch (Exception var5) {
- }
- } else {
- source = new Recordset(rs);
- }
-
- if (source != null) {
- this.m_recordset = source;
- this.setButtonEnabled(true);
- }
- }
- }
-
- }
-
- private final void releaseRowset() {
- if (this.m_recordset != null) {
- this.m_recordset = null;
- this.setButtonEnabled(false);
- ((Control)this).invalidate();
- }
-
- }
-
- public final String getDataMember() {
- return this.m_dataMember;
- }
-
- public void setDataMember(String dataMember) {
- boolean changed = false;
- if (this.m_dataMember != null) {
- if (!this.m_dataMember.equals(dataMember)) {
- changed = true;
- }
- } else if (dataMember != null) {
- changed = true;
- }
-
- if (changed) {
- this.releaseRowset();
- this.m_dataMember = dataMember;
- this.acquireRowset();
- }
-
- }
-
- protected void wndProc(Message msg) {
- switch (msg.msg) {
- default:
- super.wndProc(msg);
- case 20:
- }
- }
-
- public void onFirst(Object sender, Event e) {
- if (this.m_recordset != null) {
- try {
- this.m_recordset.moveFirst();
- } catch (Exception var4) {
- }
- }
-
- }
-
- protected void onResize(Event e) {
- Rectangle bounds = ((Control)this).getClientRect();
- this.m_first.setBounds(new Rectangle(2, 2, 20, bounds.height - 4));
- this.m_previous.setBounds(new Rectangle(22, 2, 20, bounds.height - 4));
- this.m_next.setBounds(new Rectangle(bounds.width - 20 - 2 - 20, 2, 20, bounds.height - 4));
- this.m_last.setBounds(new Rectangle(bounds.width - 20 - 2, 2, 20, bounds.height - 4));
- ((Control)this).invalidate();
- super.onResize(e);
- }
-
- protected void onPaint(PaintEvent pe) {
- Graphics g = pe.graphics;
- Rectangle bounds = ((Control)this).getClientRect();
- if (this.m_backgroundBrush == null) {
- this.m_backgroundBrush = new Brush(Color.CONTROL);
- }
-
- if (this.m_textBackgroundBrush == null) {
- this.m_textBackgroundBrush = new Brush(Color.WINDOW);
- }
-
- Rectangle textBounds = new Rectangle(bounds);
- textBounds.y += 2;
- textBounds.height -= 4;
- textBounds.x += 42;
- textBounds.width -= 84;
- g.setBrush(this.m_textBackgroundBrush);
- g.setPen((Pen)null);
- g.drawRect(textBounds);
- String text = ((Control)this).getText();
- if (text != null) {
- g.setTextColor(Color.WINDOWTEXT);
- g.setBackColor(Color.WINDOW);
- textBounds.x += 2;
- textBounds.width -= 4;
- g.drawString(text, textBounds, 36);
- }
-
- Windows.DrawEdge(g.getHandle(), bounds.toRECT(), 10, 15);
- super.onPaint(pe);
- }
-
- public void onNext(Object sender, Event e) {
- if (this.m_recordset != null) {
- try {
- this.m_recordset.moveNext();
- } catch (Exception var4) {
- }
- }
-
- }
- }
-